<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, height=device-height">
  <title>Example: browser-legacy-document-resolver</title>
</head>
<body style="white-space: pre">
<script src="https://cdn.jsdelivr.net/gh/nextapps-de/flexsearch@master/dist/flexsearch.bundle.min.js"></script>
<script>

  // some test data
  const data = [{
    "tconst": "tt0000001",
    "titleType": "short",
    "primaryTitle": "Carmencita",
    "originalTitle": "Carmencita",
    "isAdult": 0,
    "startYear": "1894",
    "endYear": "",
    "runtimeMinutes": "1",
    "genres": [
      "Documentary",
      "Short"
    ]
  },{
    "tconst": "tt0000002",
    "titleType": "short",
    "primaryTitle": "Le clown et ses chiens",
    "originalTitle": "Le clown et ses chiens",
    "isAdult": 0,
    "startYear": "1892",
    "endYear": "",
    "runtimeMinutes": "5",
    "genres": [
      "Animation",
      "Short"
    ]
  }];

  // create the document index
  const index = new FlexSearch.Document({
    document: {
      id: "tconst",
      store: true,
      index: [{
        field: "primaryTitle",
        tokenize: "forward",
        encoder: FlexSearch.Charset.LatinBalance
      },{
        field: "originalTitle",
        tokenize: "forward",
        encoder: FlexSearch.Charset.LatinBalance
      }],
      tag: [{
        field: "startYear"
      },{
        field: "genres"
      }]
    }
  });

  // add test data
  for(let i = 0; i < data.length; i++){
    index.add(data[i]);
  }

  // perform a complex query + enrich results
  let result = new FlexSearch.Resolver({
    index: index,
    query: "karmen",
    pluck: "primaryTitle"
  }).or({
    query: "clown",
    pluck: "primaryTitle"
  }).and({
    query: "not found",
    field: "originalTitle",
    suggest: true
  }).not({
    query: "clown",
    pluck: "primaryTitle"
  }).resolve({
    enrich: true
  });

  // display results
  console.log(result);
  log(JSON.stringify(result, null, 2));
  log("\n-------------------------------------\n");

  function log(str){
    document.body.appendChild(
      document.createTextNode(str + "\n")
    );
  }
</script>
</body>
</html>